package com.lry.crawlers.video.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lry.crawlers.video.entity.VideoUpdate;
import com.lry.crawlers.video.mapper.VideoUpdateMapper;
import com.lry.crawlers.video.service.VideoUpdateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VideoUpdateServiceImpl implements VideoUpdateService {
    @Autowired
    VideoUpdateMapper videoUpdateMapper;

    @Override
    public int setVideoUpdate(VideoUpdate videoUpdate) {
        return videoUpdateMapper.insert(videoUpdate);
    }

    @Override
    public List<VideoUpdate> getVideoUpdates() {
        return videoUpdateMapper.selectList(null);
    }

    @Override
    public VideoUpdate getVideoUpdate(String videoId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("video_id",videoId);
        return videoUpdateMapper.selectOne(wrapper);

    }

    @Override
    public int setVideoUpdateUp(VideoUpdate videoUpdate) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("video_id",videoUpdate.getVideoId());
        return videoUpdateMapper.update(videoUpdate,wrapper);
    }

    @Override
    public List<VideoUpdate> getVideoUpdateByVVId(Integer id) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("video_variable_id",id);
        List<VideoUpdate> list = videoUpdateMapper.selectList(wrapper);
        if(list.size()!=0)
            return list;
        else
            return null;
    }

    @Override
    public void setVideoUpdateAddNum(String videoId) {
        videoUpdateMapper.setVideoUpdateAddNum(videoId);
    }

    @Override
    public void setVideoUpdateAdd(String videoId, Integer num) {
        videoUpdateMapper.setVideoUpdateAdd(videoId,num);
    }

}
